package top.pmwly;

/**
 * @author Herther
 * @version 1.0.0
 * @ClassName ReversalSelectionSort.java
 * @Description 从后往前开始排序
 * @createTime 2021年08月15日 20:40:00
 */
public class ReversalSelectionSort {



    public static  <T extends Comparable> void sort(T[] data){
        for (int i = data.length -1; i>=0;i--){
            int max = i;
            for (int j = max;j>=0;j--){
                 if (data[j].compareTo(data[max])>0){
                     max = j;
                 }
            }
            swep(data,i,max);
        }

    }

    private static <T> void swep(T[] data, int i, int max) {
        T index =  data[i];
        data[i] = data[max];
        data[max] = index;
    }

    public static void main(String[] args) {
       Integer[] arr =  ArrayGenerate.randomGenerate(5, 10);
       sort(arr);
        for (Integer a: arr) {
            System.out.print(a+" ");

        }
    }
}
